/*
 * CSnowGenerator.h
 *
 *      Author: grifos
 */

#ifndef CSNOWGENERATOR_H_
#define CSNOWGENERATOR_H_
#include <vector>
#include <osg/Drawable>
#include <osg/ShapeDrawable>
#include <osg/Group>
#include <osg/Material>
#include <osgViewer/Viewer>
#include <osg/PositionAttitudeTransform>

#include <osg/Texture2D>
#include <osgDB/ReadFile>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/StateSetManipulator>
#include <osg/Transform>
#include <osg/MatrixTransform>
#include <osg/BlendFunc>
#include<osg/AlphaFunc>



#include <gmtl/Vec.h>
#include <gmtl/Math.h>
#include <time.h>


typedef struct S_Particle{
	gmtl::Vec3f pos;
	float lifeSpan;
	float currentLife;
	float rotType[3];
	float rotSpeed;
	int   absoluteRotSpeed;


}Particle;
class CSnowGenerator {
private:
	osg::ref_ptr<osg::Group> _root;

	int _maxParticle;
	float _life;
	float _gravity;
	float _size;
	float _sizeCoef;
	float _nbSecond; // Nombre de particule generé par seconde
	float _spawnWidth;
	int _first;
	osg::Texture2D * _snowTexture;
	osg::StateSet* _snowStateSet;
	Particle* _particles;
	osg::ref_ptr<osg::PositionAttitudeTransform> * _particlesPos;
	osg::ref_ptr<osg::MatrixTransform>* _particlesRot;
	osg::ref_ptr<osg::Geode> _particleMesh;

	void render();
	osg::ref_ptr<osg::Geode> createParticle();

public:
	CSnowGenerator(){}
	CSnowGenerator(float gravity,int nbMax, float life, float size, float width, float sizeCoef);
	virtual ~CSnowGenerator();


	void update(float time, gmtl::Vec3f spawnCenter); // On update le generateur
	void update(float time, gmtl::Vec3f spawnCenter, float speed, int mov); // On update le generateur

	osg::Group* getNode(){ return _root.get(); }

};

#endif /* CSNOWGENERATOR_H_ */
